<?php

class Application_Model_PackageList extends Application_Model_DomainObject {

      protected $_id;
      protected $_expressId;
      protected $_content;
      protected $_dateCreated;
      protected $_operator;

      public static function getFilter($name, $pagesize, $pageindex) {
            $where = array();
            if ($name != null) {
                  $where[" expressId like "] = "%" . $name . "%";
            }
            return Application_Model_PackageList::getDao()->queryPage($where, 'id desc', $pagesize, $pageindex);
      }

      public static function getshipname($expressId) {
            return Application_Model_shipType::load($expressId);
      }

      public static function getbyid($count) {
            return self::load($count);
      }

      public static function getbytime($starttime, $pagesize, $pageindex) {
            $where['dateCreated> '] = date('Y-m-d 00:00:00', strtotime($starttime));
            $where[' and dateCreated < '] = date('Y-m-d 00:00:00', strtotime($starttime) + 86400);
            return Application_Model_PackageList::getDao()->queryPage($where, 'id desc', $pagesize, $pageindex);
      }

      public static function getPageFilter($quick, $pagesize, $pageindex) {
            $where = array();
            if ($quick != "") {
                  $uwhere[" name like "] = "%" . $quick . "%";
                  $shipItem = Application_Model_shipType::getDao()->queryAll($uwhere);
                  $shipId = "";
                  foreach ($shipItem as $shipVal) {
                        $shipId.= "'" . $shipVal->id . "',";
                  }
                  $where[" expressId in "] = "(" . $shipId . "0)";
                  $where[" or operator like "] = "%" . $quick . "%";
                  $where[" or content like "] = "%" . $quick . "%";
            }
//           var_dump($where);exit;
            return self::getDao()->queryPage($where, " id desc ", $pagesize, $pageindex);
      }

      public function setOne() {
            $arrone = explode("<br />", $this->_content);
            $test = 2;
            for ($index = 0; $index < count($arrone); $index++) {
                  if (!$arrone[$index]) {
                        continue;
                  }
                  $name = $arrone[$index];
                  $result = $this->getbyContent($name);
//                  $result = self::getbyContent($name);
                  if ($result) {
                        continue;
                  }
                  $transalist = new Application_Model_PackageNo();
                  $transalist->listId = $this->_expressId;
                  $transalist->no = $name;
                  $transalist->count = $this->_id;
                  $transalist->save();
                  $test = 1;
            }
            return($test);
      }

      private function getbyContent($content) {
            $where = array();
            if ($content != null) {
                  $where["  no = "] = $content;
            }
            return Application_Model_PackageNo::getDao()->queryOne($where);
      }

      public function getshiptype() {
            return Application_Model_shipType::load($this->_expressId);
      }

      public function getPackageNo() {
            $result = Application_Model_PackageNo::getbycount($this->_id, 30, 0);
            $packageno = $result['list'];
            return count($packageno);
      }

}
